package extractor_interface

import (
	"gitee.com/guoliben/kydlp-doctotext/utils/ctrlledprint"
)

type OnTextDetectHandler func(path string, size int64, filetype string, text []byte, length int64, context interface{}) (int/*0继续匹配，非0停止匹配*/, error)
type OnStringTextDetectHandler func(path string, size int64, filetype string, text string, length int64, context interface{}) (int/*0继续匹配，非0停止匹配*/, error)

type TextExtractor interface {
	GetTextFromFile(path string, size int64, filetype string, depth int) ([]byte, string) // 磁盘模式
	GetTextFromBuffer(path string, data []byte, size int64, filetype string, depth int) ([]byte, string) // 内存模式
	/* 回调机制，在回调函数内部实现上层业务逻辑，一次提取一个文件后调用回调函数，以解决压缩文件内存堆积问题 */
	GetTextFromFileWithCallback(path string, size int64, filetype string, depth int, callback OnTextDetectHandler, context interface{}) (int, []byte, string) // 磁盘模式
	GetTextFromBufferWithCallback(path string, data []byte, size int64, filetype string, depth int, callback OnTextDetectHandler, context interface{}) (int, []byte, string) // 内存模式

	GetStringTextFromFile(path string, size int64, filetype string, depth int) (string, string) // 磁盘模式
	GetStringTextFromBuffer(path string, data []byte, size int64, filetype string, depth int) (string, string) // 内存模式
	GetStringTextFromFileWithCallback(path string, size int64, filetype string, depth int, callback OnStringTextDetectHandler, context interface{}) (int, string, string) // 磁盘模式
	GetStringTextFromBufferWithCallback(path string, data []byte, size int64, filetype string, depth int, callback OnStringTextDetectHandler, context interface{}) (int, string, string) // 内存模式
}

type FiletypeFactory interface {
	CreateTextExtractor() TextExtractor
}

type UnknownType struct{}

func (extractor UnknownType) GetTextFromFile(path string, size int64, filetype string, depth int) ([]byte, string) {
	ctrlledprint.Println(path, "未知文档忽略")
	return nil, ""
}

func (extractor UnknownType) GetTextFromBuffer(path string, data []byte, size int64, filetype string, depth int) ([]byte, string) {
	ctrlledprint.Println("未知文档忽略")
	return nil, ""
}

func (extractor UnknownType) GetTextFromFileWithCallback(path string, size int64, filetype string, depth int, callback OnTextDetectHandler, context interface{}) (int, []byte, string) {
	ctrlledprint.Println(path, "未知文档忽略")
	return 0, nil, ""
}

func (extractor UnknownType) GetTextFromBufferWithCallback(path string, data []byte, size int64, filetype string, depth int, callback OnTextDetectHandler, context interface{}) (int, []byte, string) {
	ctrlledprint.Println("未知文档忽略")
	return 0, nil, ""
}

func (extractor UnknownType) GetStringTextFromFile(path string, size int64, filetype string, depth int) (string, string) {
	ctrlledprint.Println(path, "未知文档忽略")
	return "", ""
}

func (extractor UnknownType) GetStringTextFromBuffer(path string, data []byte, size int64, filetype string, depth int) (string, string) {
	ctrlledprint.Println("未知文档忽略")
	return "", ""
}

func (extractor UnknownType) GetStringTextFromFileWithCallback(path string, size int64, filetype string, depth int, callback OnStringTextDetectHandler, context interface{}) (int, string, string) {
	ctrlledprint.Println(path, "未知文档忽略")
	return 0, "", ""
}

func (extractor UnknownType) GetStringTextFromBufferWithCallback(path string, data []byte, size int64, filetype string, depth int, callback OnStringTextDetectHandler, context interface{}) (int, string, string) {
	ctrlledprint.Println("未知文档忽略")
	return 0, "", ""
}
